// Comments are added at several places to 1a7. // This function partitions array elements to the left // and right of pivot. It is used by quick sort function. size_t part(int * data, int left, int right) { int i = left + 1, j = right; // Left item is selected as pivot. int pivot = data[left]; // This case is redundant. if(l == r && data[pivot] <= data[r]) { return pivot; } while (i <= j) { while (pivot < data[j]) j--; if (j == left) return left; else { } while (i < right && pivot > data[i]) i++; if (i == j) break; // Swapped to strictly put items to the left and right of pivot. if (i < j) swap(&data[i], &data[j]); } swap(&data[left], &data[j]); return j; }